
class Mutils {
    request(param) {
        var _this = this;
        return new Promise((resolve,reject) => {
            $.ajax({
                type: param.type || 'get',
                url: param.url || '',
                dataType :param.dataType || 'json',
                data: param.data || null,
                success(res) {
                    if(res.status === 0){
                        resolve(res);
                    }
                     // 未登录
                    else if(res.status === 10){
                       _this.doLogin();
                    }else{
                        reject(res.msg || res.data)
                    }
                },
                error(err) {
                    reject(err.statusText)
                }
            })
        })
    }
    doLogin(){
        window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
    }
    getUrlParam(name){
        let queryString = window.location.search.slice(1) || '';
        let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        let result = queryString.match(reg); // reuslt:['param=123','','123','&']
        return result ? decodeURIComponent(result[2]) : null;
    }
    successTips(successMsg){
        alert(successMsg);
    }
    errorTips(err){
        alert(err)
    }
}

export default Mutils